package com.doubao.device.controller;

import com.doubao.common.result.Result;
import com.doubao.device.dto.ApiConfigDTO;
import com.doubao.device.service.DeviceApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 智能体API配置控制器
 */
@RestController
@RequestMapping("/device/api")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "智能体API配置", description = "智能体API配置相关接口")
public class ApiConfigController {

    private final DeviceApiService apiService;

    /**
     * 获取智能体API配置
     */
    @GetMapping("/{deviceId}")
    @Operation(summary = "获取智能体API配置", description = "获取指定智能体的API配置")
    public Result<ApiConfigDTO> getDeviceApiConfig(
            @Parameter(description = "智能体ID") @PathVariable Long deviceId) {
        return apiService.getDeviceApiConfig(deviceId);
    }

    /**
     * 更新智能体API配置
     */
    @PutMapping("/{deviceId}")
    @Operation(summary = "更新智能体API配置", description = "更新指定智能体的API配置")
    public Result<Void> updateDeviceApiConfig(
            @Parameter(description = "智能体ID") @PathVariable Long deviceId,
            @RequestBody ApiConfigDTO apiConfig) {
        return apiService.updateDeviceApiConfig(deviceId, apiConfig);
    }

    /**
     * 测试智能体API连接
     */
    @PostMapping("/test/{deviceId}")
    @Operation(summary = "测试智能体API连接", description = "测试指定智能体的API连接是否正常")
    public Result<Boolean> testDeviceApiConnection(
            @Parameter(description = "智能体ID") @PathVariable Long deviceId) {
        return apiService.testDeviceApiConnection(deviceId);
    }
}